﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kimd.Motion
{
    public class PointPath
    {
        private bool _isStop = false;
        public List<Step> Steps { get; set; }
        public PointPath()
        {
            this.Steps = new List<Step>();
        }
        public void Prepare(Dictionary<string, Axis> machineAxis, Dictionary<string, Cylinder> machineCylinder, Tray tray = null, int trayIndex = -1, int nozzleIndex = -1)
        {
            foreach (var step in Steps)
            {
                step.Prepare(machineAxis, machineCylinder, tray, trayIndex, nozzleIndex);
            }
        }
        public void GoTo(Dictionary<string, Axis> machineAxis, Dictionary<string, Cylinder> machineCylinder, Dictionary<string, Sensor> machineSensor, out string errInfo, int index = -1)
        {
            _isStop = false;
            errInfo = "";
            foreach (var step in Steps)
            {
                if (_isStop)
                    break;
                if (!step.Run(machineAxis, machineCylinder, machineSensor, out errInfo))
                {
                    return;
                }
            }
        }
        public void Stop(Dictionary<string, Axis> machineAxis)
        {
            _isStop = true;
            foreach (var step in Steps)
            {
                step.Stop(machineAxis);
            }
        }
    }
}
